﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Manul.Genetics;
using System.Xml.Serialization;
using System.IO;
using System.Xml;

namespace Manul.Interface
{
    public static class IO
    {
        private static XmlSerializer serializerGenomData = new XmlSerializer(typeof(GenomData));
        public static void SaveToXml(GenomData genom, String fileName)
        {
            using (TextWriter textWriter = new StreamWriter(fileName))
            {
                serializerGenomData.Serialize(textWriter, genom);
                textWriter.Close();
            }
        }
        public static GenomData OpenFromXml(String fileName)
        {
            GenomData newGenomData = null;
            using (XmlReader xmlReader = XmlReader.Create(fileName))
            {
                newGenomData = (GenomData)serializerGenomData.Deserialize(xmlReader);
                newGenomData.UpdateEpistasis();
            }
            return newGenomData;
        }
    }
}
